//
//  SYLeftViewController.m
//  MicroNews
//
//  Created by tongcheng on 15/10/26.
//  Copyright © 2015年 siyue. All rights reserved.
//

#import "SYLeftViewController.h"
#import "SYLeftMenuView.h"
#import "SYLeftButton.h"

#import "SYBaseNavController.h"
#import "SYLoginViewController.h"
#import "DialogUtil.h"
#import "SYNewFeatureController.h"
#import "UIViewController+MMDrawerController.h"
#import "SYHomeController.h"

#import "SYMessageController.h"
#import "SYShowNewsController.h"

//定义左边菜单栏的宽、高 y
#define LeftMenuW    ScreenWidth*0.85

@interface SYLeftViewController()<SYLeftMenuViewDelegate>


@end



@implementation SYLeftViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    SYLeftMenuView *leftMenu = [[SYLeftMenuView alloc] initWithFrame:CGRectMake(0, 0,LeftMenuW+20,ScreenHeight)];
    [self.view insertSubview:leftMenu atIndex:1];
    leftMenu.delegate = self; //头像点击的代理
    self.leftMenu = leftMenu;

}

-(void)LeftUserClick:(id)sender
{
//    NSLog(@"-->小明明被点击了--------》%@",sender);
    
   

    if (UserToken==nil) {//未登录
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"UserCenterStoryboard" bundle:nil];
        SYBaseNavController *nav = [storyboard instantiateViewControllerWithIdentifier:@"SYUserCenterNavController"];
        [self presentViewController:nav animated:YES completion:nil];
        NSArray *viewControllers = nav.viewControllers;
        SYLoginViewController *vc;
        if (viewControllers.count>0) {
            vc = viewControllers[0];
        }
        [vc setDidLogin:^(NSString *message) {
            [[DialogUtil sharedInstance] showDlg:self.view textOnly:message];
        }];
    }
    else {//已登陆
        [[DialogUtil sharedInstance] showDlg:self.view textOnly:@"已登陆"];
    }
}

#pragma mark 左边菜单栏按钮点击的代理方法
-(void)leftMenu:(SYLeftMenuView *)leftMenu didSelectedFrom:(NSInteger)from to:(NSInteger)to
{
    
    NSLog(@"from-%d->leftMenu->%@-------to-》%d",from,leftMenu,to);
    
//    UIStoryboard *homeStoryboard = [UIStoryboard storyboardWithName:@"Home" bundle:nil];
//    SYHomeController *centerViewController = [homeStoryboard instantiateViewControllerWithIdentifier:@"HomeVC"];
//    SYBaseNavController * nav = [[SYBaseNavController alloc] initWithRootViewController:centerViewController];
//
    if (to == 0) {
         [self.mm_drawerController setCenterViewController:self.mm_drawerController.centerViewController withCloseAnimation:YES completion:nil];
    }else if (to == 1){
        UIStoryboard  *storyboardTwe = [UIStoryboard storyboardWithName:@"Message" bundle:nil];
        SYMessageController *message = [storyboardTwe instantiateViewControllerWithIdentifier:@"MessageVC"];
            SYBaseNavController * nav = [[SYBaseNavController alloc] initWithRootViewController:message];
        [self.mm_drawerController setCenterViewController:nav withCloseAnimation:YES completion:nil];
    
    }else if (to == 2){
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"News" bundle:nil];
        SYShowNewsController *collection = [storyboard instantiateViewControllerWithIdentifier:@"MainNewsVC"];
        SYBaseNavController * nav = [[SYBaseNavController alloc] initWithRootViewController:collection];
        [self.mm_drawerController setCenterViewController:nav withCloseAnimation:YES completion:nil];
        
    }else {
        UIViewController *set=[[UIViewController alloc]init];
        SYBaseNavController * nav = [[SYBaseNavController alloc] initWithRootViewController:set];
        [self.mm_drawerController setCenterViewController:nav withCloseAnimation:YES completion:nil];
    }


    
    
    
//    // 首页
//    UIStoryboard *homeStoryboard = [UIStoryboard storyboardWithName:@"Home" bundle:nil];
//    SYHomeController *home = [homeStoryboard instantiateViewControllerWithIdentifier:@"HomeVC"];
//    //    SYHomeController *home = [[SYHomeController alloc] init];
//    [self setupController:home title:@"新闻"];
//    
//    //2.添加控制器
//    //    SYMessageController *message=[[SYMessageController alloc]init];
//    UIStoryboard *storyboardTwe = [UIStoryboard storyboardWithName:@"Message" bundle:nil];
//    SYMessageController *message = [storyboardTwe instantiateViewControllerWithIdentifier:@"MessageVC"];
//    
//    [self setupController:message title:@"消息"];
//    //3.
//    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"News" bundle:nil];
//    SYShowNewsController *collection = [storyboard instantiateViewControllerWithIdentifier:@"MainNewsVC"];
//    [self setupController:collection title:@"收藏"];
//    //4.
//    UIViewController *set=[[UIViewController alloc]init];
//    set.view.backgroundColor = SYRandomColor;
//    [self setupController:set title:@"设置"];
//    //5.
//    UIViewController *setting=[[UIViewController alloc]init];
//    setting.view.backgroundColor = SYRandomColor;
//    [self setupController:setting title:@"跟设置"];
    
}


@end
